<?php
require_once (I('server.DOCUMENT_ROOT') .'/XgPush/XingeApp.php');

define('EXPIRETIME',86400);
define('ISOACCESSID','2200212906');
define('ISOSECRETKEY','f515e23279fbf468ee2413a7a710fa5d');
define('ANDROIDACCESSID','2100212899');
define('ANDROIDSECRETKEY','22f36ea1b233a991c76d1946f86460df');

//下发IOS设备消息
/*function PushSingleDeviceIOS($cid,$title='',$content='',$trans=array())
{
	$push = new XingeApp(ISOACCESSID, ISOSECRETKEY);
	$mess = new MessageIOS();
	$mess->setExpireTime(EXPIRETIME);
	//$mess->setSendTime("2014-03-13 16:00:00");
	$mess->setAlert(array('title'=>$title,'content'=>$content));
	$custom = array("jw"=>$trans);
	$mess->setCustom($custom);
	$ret = $push->PushSingleDevice($cid, $mess, XingeApp::IOSENV_DEV);
	return $ret;
}*/


/*function PushSingleAccountIOS($account,$title='',$content='',$trans=array())
{
	$push = new XingeApp(ISOACCESSID, ISOSECRETKEY);
	$mess = new MessageIOS();
	$mess->setExpireTime(EXPIRETIME);
	//$mess->setAlert($title);
	$mess->setAlert(array('title'=>$title,'content'=>$content));
	//$mess->setAlert(array('key1'=>'value1'));
	$custom = array("jw"=>$trans);
	$mess->setCustom($custom);
	$ret = $push->PushSingleAccount(0, $account, $mess, XingeApp::IOSENV_DEV);
	return $ret;
}*/

/*function PushAccountListIOS($accountList,$title='',$content='',$trans=array())
{
	$push = new XingeApp(ISOACCESSID, ISOSECRETKEY);
	$mess = new MessageIOS();
	$mess->setExpireTime(EXPIRETIME);
	$mess->setAlert(array('title'=>$title,'content'=>$content));
	//$mess->setAlert(array('key1'=>'value1'));

	$custom = array("jw"=>$trans);
	$mess->setCustom($custom);

	$ret = $push->PushAccountList(0, $accountList, $mess, XingeApp::IOSENV_DEV);
	return ($ret);
}*/

function PushSingleDevice($cid,$title='',$content='',$trans=array())
{
	print_r($cid);
	$push = new XingeApp(ANDROIDACCESSID, ANDROIDSECRETKEY);
	$mess = new Message();
	$mess->setTitle($title);
	$mess->setContent($content);
	$mess->setStyle(new Style(1,1,1,1,0)); 

	$custom = $trans;
	$mess->setCustom($custom);
	$mess->setType(Message::TYPE_NOTIFICATION);
	$ret = $push->PushSingleDevice($cid, $mess);
	return $ret;
}

//下发单个账号

function PushSingleAccount($account,$title='',$content='',$trans=array())
{
	$push = new XingeApp(ANDROIDACCESSID, ANDROIDSECRETKEY);
	$mess = new Message();
	$mess->setExpireTime(EXPIRETIME);
	$mess->setTitle($title);
	$mess->setContent($content);
	$mess->setStyle(new Style(1,1,1,1,0)); 

	$custom = $trans;
	$mess->setCustom($custom);
	$mess->setType(Message::TYPE_NOTIFICATION);
	$ret = $push->PushSingleAccount(0, $account, $mess);
	return ($ret);
}

//下发多个账号， IOS下发多个账号参考Demo PushSingleAccountIOS 进行相应修改
function PushAccountList($accountList,$title='',$content='',$trans=array())
{
	print_r($accountList);
	$push = new XingeApp(ANDROIDACCESSID, ANDROIDSECRETKEY);
	$mess = new Message();
	$mess->setExpireTime(EXPIRETIME);
	$mess->setTitle('title');
	$mess->setContent('content');
	$mess->setStyle(new Style(1,1,1,1,0)); 
	$custom = $trans;
	$mess->setCustom($custom);
	$mess->setType(Message::TYPE_NOTIFICATION);
	$ret = $push->PushAccountList(0, $accountList, $mess);
	return ($ret);
}



//下发所有设备
function PushAllDevices($title='',$content='',$trans=array())
{
	$push = new XingeApp(ANDROIDACCESSID, ANDROIDSECRETKEY);
	$mess = new Message();
	$mess->setType(Message::TYPE_NOTIFICATION);
	$mess->setTitle($title);
	$mess->setContent($content);
	$mess->setStyle(new Style(1,1,1,1,0)); 

	$mess->setExpireTime(EXPIRETIME);
	$custom = $trans;
	$mess->setCustom($custom);
	$ret = $push->PushAllDevices(0, $mess);
	return ($ret);
}

//下发所有设备
/*function PushAllDevicesIOS($title='',$content='',$trans=array())
{
	$push = new XingeApp(IOSACCESSID, IOSSECRETKEY);
	$mess = new MessageIOS();
	$mess->setExpireTime(EXPIRETIME);

	$mess->setAlert(array('title'=>$title,'content'=>$content));
	//$mess->setAlert(array('key1'=>'value1'));
	$custom = array("jw"=>$trans);
	$mess->setCustom($custom);;
	$ret = $push->PushAllDevices(0, $mess,XingeApp::IOSENV_DEV);
	return ($ret);
}*/


//大批量下发给设备 android
//iOS 请构建MessageIOS 消息
function PushDeviceListMultipleNotification($accountList,$title='',$content='',$trans=array())
{
	$push = new XingeApp(ANDROIDACCESSID, ANDROIDSECRETKEY);
	$mess = new Message();
	$mess->setExpireTime(EXPIRETIME);
	$mess->setTitle($title);
	$mess->setContent($content);
	$mess->setType(Message::TYPE_NOTIFICATION);
	$mess->setStyle(new Style(1,1,1,1,0)); 
	
	$custom = $trans;
	$mess->setCustom($custom);
	$ret = $push->CreateMultipush($mess);
	if (!($ret['ret_code'] === 0))
		return $ret;
	else
	{
		$result=array();
		print_r($accountList);
		array_push($result, $push->PushDeviceListMultiple($ret['result']['push_id'], $accountList));
		return ($result);
	}
}

/*function PushDeviceListMultipleNotificationIOS($accountList,$title='',$content='',$trans=array())
{
	$push = new XingeApp(ISOACCESSID, ISOSECRETKEY);
	$mess = new MessageIOS();
	$mess->setExpireTime(EXPIRETIME);
	//$mess->setSendTime("2014-03-13 16:00:00");
	
	$mess->setAlert(array('title'=>$title,'content'=>$content));
	$custom = array("jw"=>$trans);
	$mess->setCustom($custom);
	$ret = $push->CreateMultipush($mess, XingeApp::IOSENV_DEV);
	if (!($ret['ret_code'] === 0))
		return $ret;
	else
	{
		$result=array();
		array_push($result, $push->PushDeviceListMultiple($ret['result']['push_id'], $accountList));
		return ($result);
	}
}*/




